package com.cuit.dao;

import com.cuit.doamin.Department;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DepartmentDao {
    /**
     * 增加一个部门
     *
     * @return
     */
    @Insert("insert into department (d_id,d_name) values (#{d_id},#{d_name})")
    public boolean add(Department department);

    /**
     * 删除一个部门,动态SQL
     *
     * @return
     */

    @Delete({"<script> " +
            "delete from department " +
            "where  1=1 " +
            "<if test='d_id!=null and d_id!=&apos; &apos;'> and d_id = #{d_id}</if> " +
            "<if test='d_name!=null'> and d_name = #{d_name}</if> " +
            "</script>"})
    public boolean delete(Department department);

    /**
     * 修改一个部门
     *
     * @return
     */
    @Update("update department set d_name = #{d_name} where d_id = #{d_id}")
    public boolean update(Department department);

    /**
     * 查询所有部门
     *
     * @return
     */
    @Select("select * from department")
    public List<Department> findAll();
}
